#include "logger.h"
#include <iostream>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/RemoteSyslogAppender.hh>
#include <log4cpp/PropertyConfigurator.hh>

Logger::Logger()
{

}

Logger::~Logger()
{
    if(Instance)
        delete Instance;
}

Logger *Logger::Instance = nullptr;
bool Logger::init(std::string log_file_path)
{
    try{
        log4cpp::PropertyConfigurator::configure(log_file_path);
    }catch(log4cpp::ConfigureFailure &f){
        std::cerr << "load log config file " << log_file_path.c_str() << " and fail reason " <<  f.what() << std::endl;
        return false;
    }
    
    _category = &log4cpp::Category::getRoot();
    
    return true;
}

Logger *Logger::getInstance()
{
    if(!Instance)
        Instance = new Logger();
    
    return Instance;
}

log4cpp::Category *Logger::getHandle()
{
    return this->_category;
}




